<template>
  <div style="display: flex">
    <div style="width: 48%">
      <div>
        <div style="display: flex">
          <span style="width: 60px">路径：</span>
<!--          <el-input v-model="reqUrl" style="width: 440px"/>-->
          <el-select v-model="reqUrl" placeholder="请选择" style="width: 440px" >
            <el-option
              v-for="item in reqUrlList"
              :key="item"
              :value="item">
            </el-option>
          </el-select>
        </div>
<!--        <div style="display: flex">-->
<!--          <span style="width: 60px">方式：</span><el-input v-model="reqModel" style="width: 120px"/>-->
<!--        </div>-->
      </div>
      <div>
        <div>参数输入：
          <el-button-group v-if="reqUrl==='/circuitDesign/generate/paramTips'">
            <el-button type="primary" size="small" @click="reqParam1P">reqParam1</el-button>
            <el-button type="primary" size="small" @click="reqParam10P">reqParam10</el-button>
            <el-button type="primary" size="small" @click="reqParam20P">reqParam20</el-button>
            <el-button type="primary" size="small" @click="reqParam30P">reqParam30</el-button>
          </el-button-group>
          <el-button-group v-if="reqUrl==='/circuitDesign/generate/circuitGeneration'">
            <el-button type="primary" size="small" @click="reqParam10P">reqParam10</el-button>
            <el-button type="primary" size="small" @click="reqParam20P">reqParam20</el-button>
            <el-button type="primary" size="small" @click="reqParam30P">reqParam30</el-button>
            <el-button type="primary" size="small" @click="circuitGenerationP">reqParam</el-button>
          </el-button-group>
        </div>
        <el-form>
          <el-form-item prop="reqParam">
            <vue-json-editor v-model="reqParam" />
          </el-form-item>
        </el-form>
      </div>


    </div>
    <div style="width: 48%">
      <div><el-button type="primary" @click="goPost">发送post请求</el-button></div>
      <div>结果返回</div>
      <vue-json-editor :mode="'code'" v-model="resMsg" />
    </div>

  </div>
</template>
<script>
import {postGo} from "@/api/expert/circuit";
import vueJsonEditor from 'vue-json-editor'
export default {
  name: "test3",
  components:{vueJsonEditor},
  data(){
    return{
      reqUrl:'/circuitDesign/generate/paramTips',
      reqUrlList:[
        '/circuitDesign/generate/paramTips',
        '/circuitDesign/generate/circuitGeneration'
        ],
      // reqModel:'post',
      reqParam10:[{
        "qualitygrade":"Industrial", // 质量等级
        "bus":"CAN", // 总线通信类型
        "volt":"48",  // 电压等级
        "controller":"DSP", // 处理器的类型
        "power":"5", // 最大功率
        "page":"1.0" // 当前参数页码
      }],
      reqParam20:[{
        "qualitygrade":"Industrial", // 质量等级
        "bus":"CAN", // 总线通信类型
        "volt":"48",  // 电压等级
        "controller":"DSP", // 处理器的类型
        "power":"5", // 最大功率
        "analoguetype":"1", // 采集类型
        "signalmin":"10", // 最小频率
        "signalmax":"20", // 最大频率
        "mindatarange":"10", // 最小输入范围
        "maxdatarange":"20", // 最大输入范围
        "sample":"100", // 采样率
        "samplingbit":"24.0", // 采样分辨率
        "samplinglength":"100",  // 采样长度
        "page":"2.1" // 当前参数页码
      }],
      reqParam30:[{
        "qualitygrade":"Industrial", // 质量等级
        "bus":"CAN", // 总线通信类型
        "volt":"48",  // 电压等级
        "controller":"DSP", // 处理器的类型
        "power":"5", // 最大功率
        "intype":"c", // 数字电路类型
        "involt":"5", // 输入信号电压
        "page":"3.1" // 当前参数页码
      }],
      reqParam1:[{
        "page":"1.0" // 当前参数页码
      }],
      reqParam:null,
      resMsg: null,
      circuitGenerationParam:{
        "bus":{"code":"USB","name":"数据总线接口类型（处理器接口）"},
        "volt":{"code":48,"name":"供电电压（电源输入电压）"},
        "analoguenum":{"code":1,"name":"模拟采样通道数量"},
        "digitalnum":{"code":1,"name":"数字采样通道数量"},
        "controller":{"code":"MCU","name":"处理器类型"},
        "prior":{"code":"balance","name":"设计考虑"},
        "qualitygrade":{"code":"Industrial","name":"质量等级"},
        "power":{"code":3,"name":"最大功率（电源最大功率）"},
        "analogue":[{
          "analogueno":{"code":1,"name":"第一通道"},
          "analoguename":{"code":"v1","name":"通道名称"},
          "analoguetype":{"code":1,"name":"通道采集类型（电压：1、温度：4）"},
          "sample":{"code":10,"name":"采样率"},
          "signalmax":{"code":20,"name":"最高频率"},
          "signalmin":{"code":10,"name":"最低频率"},
          "maxdatarange":{"code":20,"name":"最大输入"},
          "mindatarange":{"code":10,"name":"最小输入"},
          "samplingbit":{"code":8,"name":"采样精度"},
          "samplinglength":{"code":100,"name":"采样长度"}
        }],
        "digital":[{
          "digitalno":{"code":1,"name":"第一通道"},
          "digitalname":{"code":"d1","name":"通道名称"},
          "intype":{"code":"c","name":"源型"},
          "involt":{"code":5,"name":"信号电压"}
        }],
        mainProjectId:'123'
      }
    }
  },
  methods: {
    circuitGenerationP(){
      this.reqParam = this.circuitGenerationParam
    },
    reqParam1P(){
      this.reqParam = this.reqParam1
    },
    reqParam10P(){
      this.reqParam = this.reqParam10
    },
    reqParam20P(){
      this.reqParam = this.reqParam20
    },
    reqParam30P(){
      this.reqParam = this.reqParam30
    },
    goPost(){
      let pa = null
      if(this.reqUrl === '/circuitDesign/generate/paramTips'){
        pa = {"param":JSON.stringify(this.reqParam),"mainProjectId":"123"}
      }
      if(this.reqUrl === '/circuitDesign/generate/circuitGeneration'){
        this.reqParam.mainProjectId = "123"
        pa = {"param":JSON.stringify(this.reqParam)}
      }
      postGo(this.reqUrl,pa).then(o=>{
          let r = o
          r.data = JSON.parse(o.data)
          this.resMsg = r
      })
    }
  }
}
</script>

